<?php

namespace App\Service\SiteLocation\Import;

use App\Exceptions\Custom\ResponseHttpException;
use App\Exceptions\KfHttpResponseException;
use App\Models\Common\MapNationalBrandShopModel;
use App\Models\OpenShop\Common\MallSettleInShopInfoModel;
use App\Models\Wanggui\BusinessAoiModel;
use App\Models\Wanggui\WangguiDotYhatModel;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;

class BusinessCircleWorth
{
    public function collection(Collection $collection, ?Command $command)
    {
        $num = 0;
        $collection->first()->map(function ($dot) use (&$num) {
            if ($num == 0) {
                $header = [
                    "省",
                    "市",
                    "区",
                    "商圈名称",
                    "夸父炸串",
                    "商圈人口",
                    "预估夸父能开门店数（3W人/店）",
                    "店均实收",
                    "商圈价值（月总实收）",
                    "城市价值",
                    "重点城市",
                ];
                foreach ($header as $key => $value) {
                    if ($dot[$key] != $value) {
                        return;
                    }
                }
                $num++;
                return;
            }

            if ($dot[0] == null) {
                return;
            }

            BusinessAoiModel::query()
                ->where('province', $dot[0])
                ->where('city', $dot[1])
                ->where('district', $dot[2])
                ->where('name', $dot[3])
                ->get()
                ->map(function (BusinessAoiModel $businessAoiModel) use ($dot){
                    $businessAoiModel->capacity   = round($dot[6], 0);
                    $businessAoiModel->population = round($dot[5], 0);
                    $businessAoiModel->worth      = round($dot[8], 0);
                    $businessAoiModel->cityWorth  = round($dot[9], 0);
                    $businessAoiModel->save();
                });

            dump($num);
            $num++;
        });
    }
}
